<!--执行详情-多币对-->
<template>
  <div @viewappear="viewappear" @rightBtn="rightBtn">
    <scroller class="scroller">

      <div class="wrapper bg1" v-if="menus">
        
        <!--跟单-基础信息-->
        <div class="column" v-if="detailMap.isFollow">
          <div class="row acenter">
            <div class="row aend">
              <text class="font32 text1">{{detailMap.followName ? T(detailMap.followName) : T(detailMap.strategyName)}}</text>
              <text class="font24 text3" v-if="detailMap.strategyCode">{{'  '+detailMap.strategyCode}}</text>
            </div>
            <div class="all"></div>
            <text class="font28 text1">{{T('跟单佣金')+':'+detailMap.commission+'VTN/日'}}</text>
          </div>

          <div class="height20"></div>
          <text class="font24 text3">{{parseTime1(detailMap.startTime)+'-('+getExecuteTime(detailMap.startTime)+')'}}</text>
          
          <div class="line bg3"></div>

          <div class="row acenter" @click="userClick(detailMap.followUserId)">
          <LImage class="image" :src="detailMap.avatar ? detailMap.avatar : Config.img('view_image_portrait_normal.png')"></LImage>  
          <text class="font32 text1">{{detailMap.nickName}}</text>
          <div class="all"></div>
          <LImage class="arrow" :src="Config.img('strategy_arrow.png')"></LImage>
          </div>
        </div>
        
        <!--其他-基础信息-->
        <div class="column" v-else>

          <div class="row acenter">
            <div class="row aend">
              <text class="font32 text1">{{detailMap.followName ? T(detailMap.followName) : T(detailMap.strategyName)}}</text>
              <text class="font24 text3" v-if="detailMap.strategyCode">{{'  '+detailMap.strategyCode}}</text>
            </div>
            <div class="all"></div>
            <text :class="['font28', (detailMap.states == 'EXECUTE' ?  'main-t1' : 'text3')]">{{getStateStr(detailMap.states)}}</text>
          </div>

          <div class="height20"></div>
          <div class="row aend">
            <text class="font24 text3">{{parseTime1(detailMap.startTime)+'-('+getExecuteTime(detailMap.startTime)+')'}}</text>
            <div class="all"></div>
            <text class="font28 text3" v-if="detailMap.isOpenFollow==true">{{T("开放跟单")}}</text>
          </div>
        </div>


        <!--投入数据-->
        <div class="line bg3"></div>
        <div class="column">
          <text class="font24 text2 " >{{getExchangeName()}}</text>

          <div class="height20"></div>
          <div class="row">
            <text class="font24 text3">{{T('总投入')+'('+pair.investCoin+')'}}</text>
            <div class="all"></div>
            <text class="font24 text3">{{T('总收益')+'('+pair.investCoin+')'}}</text>
          </div>

          <div class="height20"></div>
          <div class="row">
            <text class="font32 text2">{{pair.investCoinnNum}}</text>
            <div class="all"></div>
            <text :class="['font32', Config.upDownFont(redisMap.realEarnings)]">{{redisMap.realEarnings + '(' +math.addJia(redisMap.realEarningsRate) + '%)'}}</text>
          </div>
        </div>
        
        <!--收益信息-->
        <div class="line bg3"></div>
        <div class="row all">
          <div class="column all">
            <text class="font24 text3">{{T('实现盈亏')+'('+pair.investCoin+')'}}</text>
            <text :class="['font24', Config.upDownFont(redisMap.earnings)]">{{math.addJia(redisMap.earnings)}}</text>
            <text :class="['font24', Config.upDownFont(redisMap.earnings)]">{{math.addJia(redisMap.earningsRate)+'%'}}</text>
          </div>
          <div class="column all">
            <text class="font24 text3">{{T('浮动盈亏')+'('+pair.investCoin+')'}}</text>
            <text :class="['font24', Config.upDownFont(redisMap.floatEarnings)]">{{math.addJia(redisMap.floatEarnings)}}</text>
            <text :class="['font24', Config.upDownFont(redisMap.floatEarnings)]">{{math.addJia(redisMap.floatEarningsRate)+'%'}}</text>
          </div>
          <div class="column all aend">
            <text class="font24 text3">{{T('实现年化')+'/'+T('总年化')}}</text>
            <text :class="['font24', Config.upDownFont(detailMap.yearIncome)]">{{math.addJia(detailMap.yearIncome)+'%'}}</text>
            <text :class="['font24', Config.upDownFont(detailMap.realYearIncome)]">{{math.addJia(detailMap.realYearIncome)+'%'}}</text>
          </div>
        </div>

        <!--交易数-->
        <div class="line bg3"></div>
        <div class="row all">
          <div class="column all">
            <text class="font24 text3">{{T('累计买入')}}</text>
            <text class="font24 text2">{{redisMap.finishBuyCount}}</text>
          </div>
          <div class="column all">
            <text class="font24 text3">{{T('累计卖出')}}</text>
            <text class="font24 text2">{{redisMap.finishSellCount}}</text>
          </div>
          <div class="column all aend">
            <text class="font24 text3">{{T('交易数')}}</text>
            <text class="font24 text2">{{redisMap.finishBuySellCount}}</text>
          </div>
        </div>
        
        <!--收益走势图-->
        <div class="line bg3"></div>
        <div class="column">
          <div class="row acenter">
            <text class="font28 text1">{{T('收益分析')}}</text>
            <div class="all"></div>
            <div class="line-chart-color main1"></div>
            <text class="font24 text2">{{T("总收益率")}}</text>
          </div>
          <WeexLineChart class="line-chart" :data="lineChartData"></WeexLineChart>
        </div>

        <!--止盈止损-->
        <div class="line bg3"></div>
        <div class="column">
          <text class="font28 text1">{{T('止盈止损')}}</text>
          <div class="height20"></div>
          <div class="row all">
            <div class="column all">
              <text class="font24 text3">{{T('策略止盈率')}}</text>
              <text class="font24 text2">{{stopProfit}}</text>
            </div>

            <div class="column all">
              <text class="font24 text3">{{T('策略止损率')}}</text>
              <text class="font24 text2">{{stopLoss}}</text>
            </div>

            <div class="column all aend">
              <text class="font24 text3">{{T('自动终止时间')}}</text>
              <text class="font24 text2">{{stopTime}}</text>
            </div>
          </div>
        </div>

        <!--持仓-->
        <div class="line bg3"></div>
        <template>
          <text class="font28 text1">{{T('持仓')}}</text>
          <div class="height40"></div>

          <!-- 标题 -->
          <div class="row">
            <text class="font24 text3 all3">{{T('币种')}}</text>
            <text class="font24 text3 all3">{{T('数量')}}</text>
            <text class="font24 text3 all3">{{T('浮动盈亏')}}</text>
            <text class="font24 text3 text-right all3">{{T('开仓均价')+redisMap.inverstCoin}}</text>
          </div>
          
          <!-- 本币行 -->
          <div class="cell">
            <text class="font24 text2 all3">{{redisMap.inverstCoin}}</text>
            <text class="font24 text2 all3">{{allInvestNum}}</text>
            <text class="font24 text2 all3">{{'--'}}</text>
            <text class="font24 text2 text-right all3">{{'--'}}</text>
          </div>
          <div class="line3 bg3"></div>
          
          <!-- 持仓列表 -->
          <template v-for="(item, index) in holdList">
            <div class="cell" v-bind:key="index" @click="cellClick(item)">
              <div class="all3">
                <text class="font24 text2 all3">{{redisMap.inverstCoin == item.baseCoin ? item.counterCoin: item.baseCoin}}</text>
                <text class="font20 text3" v-if="item.states!='EXECUTE' && !detailMap.isFollow">{{getStateStr(item.states)}}</text>
              </div>
              <text class="font24 text2 all3">{{redisMap.inverstCoin == item.baseCoin ? Config.toNonNum(item.counterCoinTotal) : Config.toNonNum(item.baseCoinTotal)}}</text>
              <text :class="['font24',  'all3', Config.upDownFont(item.profitLoss)]">{{item.profitLoss}}</text>
              <text class="font24 text2 text-right all3">{{math.getNumber(item.costPrice) == 0 ? '--' : item.costPrice}}</text>
            </div>
            <div class="line3 bg3" v-bind:key="'line3'+index"></div>
          </template>
        </template>
      </div>
    </scroller>

    <!-- 菜单 -->
    <div class="menu" v-if="showMenu" @click="hideClick">
      <div class="meun-content bg3">
        <text class="font24 text2 meun-text" v-for="(item, index) in menus" v-bind:key="index" @click="menuClick(item)">{{T(item)}}</text>
      </div>
    </div>

    <div class="tc" v-if="isTc">
      <div class="all" @click="tcClick"></div>
      <div class="tc-content bg2">
        <div class="cell">
          <text class="font28 text2 all text-center" v-if="!detailMap.isFollow && tcItem.states!='EXECUTE'">{{(redisMap.inverstCoin == tcItem.baseCoin ? tcItem.counterCoin: tcItem.baseCoin)+'-'+T('持仓操作')+ '（' + getStateStr(tcItem.states) + '）'}}</text>
          <text class="font28 text2 all text-center" v-else>{{(redisMap.inverstCoin == tcItem.baseCoin ? tcItem.counterCoin: tcItem.baseCoin)+'-'+T('持仓操作')}}</text>
        </div>
        <div class="line3 bg3"></div>
        <div class="cell" v-for="(item, index) in tcs"  v-bind:key="'tc'+index" @click="tcCell(item)">
          <text class="font28 text1 all text-center">{{T(item)}}</text>
        </div>
        <div class="cell" @click="tcClick">
          <text class="font26 text2 all text-center">{{T('取消')}}</text>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import navigator from "@/_js/navigator";
import modal from "@/_js/modal";
import math from "@/_js/math";
import amStrategy2 from "@/strategy/amStrategy2";
import Config from "@/_js/config";
import broadcast from "@/_js/broadcast";

const weexFunction = weex.requireModule("WeexFunction");
import weexHttp from "@/_js/https"; ;

import I18N from "@/_i18n/i18n";
var T = I18N.t;
weexFunction.setTitle(T("执行详情"));
weexFunction.setRightBtn(T("功能"));

//执行详情
export default {
  
  data() {
    return {
      T: T,
      math: math,
      Config: Config,
      showMenu: false, //显示菜单
      menus: undefined, //菜单
      executeId: "", //执行id
      manyMimic:false, //turn 模拟盘支持增加币对

      allInvestNum:0,//投资币总数量
      allLock:0,//投资币总冻结
      allLockRate:0,

      detailMap: undefined, //执行信息
      redisMap: undefined, //数据库信息
      configMap: undefined, //执行配置
      followMap: undefined, //限制-跟单配置
      pair:undefined, //交易对
      lineChartData:undefined, //收益走势
      followMimic: false, //turn 模拟盘开放跟单


      stopProfit: "", //止盈
      stopLoss: "", //止损
      stopTime: "", //自动终止时间

      buyList: [], //委托买单列表
      sellList: [], //委托卖单列表

      isTc:false,
      tcItem:undefined,
      tcs:[],
    };
  },

  mounted() {

    Config.init(() => {
      this.executeId = navigator.getParam("executeId");
      this.httpExecuteDetail();
    }, [Config.OPT_UP_DOWN]);

    //刷新订阅
    broadcast.subscribe('RunInfos', broadcast.EXECUTE_UPDATE, ()=>{
      this.httpExecuteDetail();
    });
  },

  methods: {

    //初始菜单
    initMenu() {

      this.menus = ['参数', '暂停', '加仓', '终止', "增加币对", "历史记录"];
      if (this.detailMap.isFollow){
        this.menus = ['加仓', '终止', "历史记录"];
      } else if (this.detailMap.states == "SUSPEND") { //暂停状态
        this.menus = ['参数', '重启', '加仓', '终止', "增加币对", "历史记录"];
      }
    },

    /*************************************************通信触发*/
    //完全显示
    viewappear() {
      this.allInvestNum = 0;//投资币总数量
      this.allLock = 0;//投资币总冻结
      this.allLockRate = 0;
      this.httpExecuteDetail();
    },

    //右按钮触发
    rightBtn() {
      this.menus&&(this.showMenu = !this.showMenu);
    },

    /********************************** HTTP*/
    //http策略库
    httpExecuteDetail() {
      if (this.executeId == '') {
        return;
      }
      
      this.allInvestNum = 0;//投资币总数量
      this.allLock = 0;//投资币总冻结
      this.allLockRate = 0;
      var param = {executeId: this.executeId };
      weexHttp.post("strategyV3/executeDetail", param, true, (data) => {

          if (data.status == 200) {
            data = data.data;
            this.redisMap = data.redisMap;
            this.detailMap = data.executeDetail;
            this.followMap = data.followMap;
            this.configMap = data.executeDetail.config;
            this.holdList = data.sonExecuteList;
            this.manyMimic = data.manyMimic;
            this.followMimic = data.followMimic;
            

            //收益曲线
            var realEarningsLine = this.redisMap.realEarningsLine;
            this.lineChartData = realEarningsLine ? realEarningsLine.items : [];
            
            //复制交易对-避免截取总投入时，加仓、减仓一次问题。
            this.pair = JSON.parse(JSON.stringify(this.configMap.tradePairs[0]));
            var xiaoshu = math.getCoin(this.pair.investCoin);

            //总投入
            this.pair.investCoinnNum = math.xiaoshu(this.pair.investCoinnNum, xiaoshu, 2);

            //总盈亏
            this.redisMap.realEarnings = math.xiaoshu(this.redisMap.realEarnings, xiaoshu, 2);
            this.redisMap.realEarningsRate = math.xiaoshu(this.redisMap.realEarningsRate, 2, 2);

            //浮动盈亏
            this.redisMap.floatEarnings = math.xiaoshu(this.redisMap.floatEarnings, xiaoshu, 2);
            this.redisMap.floatEarningsRate = math.xiaoshu(this.redisMap.floatEarningsRate, 2, 2);

            //实现盈亏
            this.redisMap.earnings = math.xiaoshu(this.redisMap.earnings, xiaoshu, 2);
            this.redisMap.earningsRate = math.xiaoshu(this.redisMap.earningsRate, 2, 2);

            //交易数量
            this.redisMap.finishBuyCount = this.redisMap.finishBuyCount ? this.redisMap.finishBuyCount : "0";
            this.redisMap.finishSellCount = this.redisMap.finishSellCount ? this.redisMap.finishSellCount : "0";
            this.redisMap.finishBuySellCount = math.jia(this.redisMap.finishBuyCount, this.redisMap.finishSellCount);

            //止盈止损
            this.configMap.stopProfit = this.configMap.stopProfit?this.configMap.stopProfit:'';
            this.stopProfit = this.configMap.stopProfit.length > 0 ? (math.cheng(this.configMap.stopProfit, '100') + '%') : '--';
            this.configMap.stopLoss = this.configMap.stopLoss?this.configMap.stopLoss:'';
            this.stopLoss = this.configMap.stopLoss.length > 0 ? (math.cheng(this.configMap.stopLoss, '-100') + '%') : '--';
            this.configMap.stopTime = this.configMap.stopTime?this.configMap.stopTime:'';
            this.stopTime = this.configMap.stopTime.length > 0 ? this.parseTime1(math.getNumber(this.configMap.stopTime)) : '--';

            //交易币、本币、投资币
            this.redisMap.inverstCoin = this.redisMap.inverstCoin.toUpperCase();
            
            for (let index = 0; index < this.holdList.length; index++) {
              
              var map = this.holdList[index];
              map.isShow = false;
              map.baseCoin = map.baseCoin.toUpperCase();
              map.counterCoin = map.counterCoin.toUpperCase();

              if (map.baseCoinTotal == undefined) {
                map.counterCoinTotal = '0';
                map.baseCoinTotal = '0';
                map.baseCoinFreez = '0';
                map.counterCoinFreez ='0';
                map.price ='0';
                map.costPrice='0';
              }


              //算出冻结率
              var bRate = math.chu(map.baseCoinFreez,map.baseCoinTotal);
              bRate  = math.getNumber(bRate ) > 1 ? '1' : bRate;
              map.baseCoinFreezRate = math.cheng(bRate ,'100', 2, 2)+"%";

              var cRate = math.chu(map.counterCoinFreez,map.counterCoinTotal);
              cRate  = math.getNumber(cRate ) > 1 ? '1' : cRate;
              map.counterCoinFreezRate = math.cheng(cRate, '100', 2, 2) +"%";

              if (map.baseCoin.toUpperCase() == "BTC") {
                map.baseCoinTotal = math.xiaoshu(map.baseCoinTotal, 6, 2);
              } else {
                map.baseCoinTotal = math.xiaoshu(map.baseCoinTotal, 4, 2);
              }

              if (map.counterCoin.toUpperCase() == "BTC") {
                map.counterCoinTotal = math.xiaoshu(map.counterCoinTotal,6,2);
              } else {
                map.counterCoinTotal = math.xiaoshu(map.counterCoinTotal,4,2);
              }

              //浮动盈亏
              var length = math.getCoin(this.redisMap.inverstCoin);
              var profitLoss;
              if (this.redisMap.inverstCoin == map.baseCoin) {
                var price = math.jian(map.price, map.costPrice);
                profitLoss = math.cheng(price,map.counterCoinTotal,length, 2);
              } else {
                  var cost = math.chu(map.baseCoinTotal, map.costPrice); //成本价
                  var cur = math.chu(map.baseCoinTotal, map.price); //当前价
                  profitLoss = math.jian(cost, cur, length, 2);
              }
              map.profitLoss = profitLoss;
              this.holdList[index].profitLoss = profitLoss;


              //浮动盈亏率
              var profitLossRate;
              if (this.redisMap.inverstCoin == map.baseCoin.toUpperCase()) {
                var price = math.jian(map.price, map.costPrice);
                profitLossRate = math.chu(price, map.costPrice, 4, 2);
              } else {
                var price = math.jian(map.costPrice, map.price);

                profitLossRate = math.chu(price, map.costPrice, 4, 2);
              }
              profitLossRate = math.cheng(profitLossRate, "100", 2);
              map.profitLossRate = profitLossRate;
              
              //开仓均价
              map.costPrice = math.xiaoshu(map.costPrice, this.pair.baseCoinDecimal, 2);
            }
            var num = this.redisMap.group_keep.total;//获取投资币剩余（可用+冻结）
            var lock = this.redisMap.group_keep.freez;//获得投资币冻结

            this.allInvestNum = math.xiaoshu(num, length, 2);
            var rate = math.chu(lock,num);

            this.allLockRate = math.cheng(rate,"100",2, 2)+"%";
            

            this.initMenu();
          } else {
            modal.toast(data.msg);
          }
        }
      );
    },

    /********************************** GET*/
    //获得策略状态字符
    getStateStr(states) {

      if (states == "EXECUTE") {
        return T("执行中");
      }

      if (states == "SUSPEND") {
        return T("已暂停");
      }

      if (states == "STARTING") {
        return T("启动中");
      }

      if (states == "STOPING") {
        return T("正在终止");
      }
    },

    
    //获交易所名称
    getExchangeName(){
      var remark = this.detailMap.remark && this.detailMap.remark.length ? ('·' + this.detailMap.remark) : '';
      return this.pair.apiName + remark + '（' + T('多币对') + ' ' + this.detailMap.childCount + '）';
    },
  
    //时间转换(年月日时分)
    parseTime1(timestamp) {
      var time = new Date(Number(timestamp));

      var year = time.getFullYear();

      var month = time.getMonth() + 1;
      month = month < 10 ? "0" + month : month;

      var day = time.getDate();
      day = day < 10 ? "0" + day : day;

      var hour = time.getHours();
      hour = hour < 10 ? "0" + hour : hour;

      var minute = time.getMinutes();
      minute = minute < 10 ? "0" + minute : minute;

      return year + "/" + month + "/" + day + " " + hour + ":" + minute;
    },

    //获取执行时长
    getExecuteTime(startTime) {
      var time = new Date().getTime();
      var disTime = time - startTime;
      var day = Math.floor(disTime / 86400000);
      var hour = Math.floor((disTime % 86400000) / 3600000);
      var min = Math.floor(((disTime % 86400000) % 3600000) / 60000);
      return day + T("天") + hour + T("时") + min + T("分");
    },

    //获取参数值
    getParamValue(name) {

      var params = this.configMap.reserves;
      for (let index = 0; index < params.length; index++) {
        var param = params[index];
        if (param.name == name) {
          return( param.value + '');
        }
      }
      return undefined;
    },

    /********************************** 点击事件*/
    errorMsg(item) {
      item.errorInfo = false;
      navigator.open(T('策略消息'), 'strategy/StrategyNotice', {stId:item.executeId});
    },

    //隐藏
    hideClick() {
      if (this.detailMap == undefined) {
        return;
      }
      this.showMenu = false;
    },

    //图片点击
    imgClick(item) {
      item.isShow = !item.isShow;
      this.$forceUpdate();
    },

    //持仓列表点击
    cellClick(item) {
      if (this.detailMap.isFollow) return;
      if (item.states == 'STOPING') {
            modal.toast(T('终止中无法操作'));
        return;
      }


      this.tcItem = item;
      this.tcs = item.states == 'SUSPEND' ? ['消息', '参数', '重启', '终止', '详情'] : ['消息', '参数', '暂停', '终止', '详情'];
      this.isTc = true;
    },

    //持仓弹出点击
    tcCell(item) {
      this.isTc = false;
      if (item == '消息'){
        this.msgClick(this.tcItem.exchangeId)
      } else if (item == '参数'){
        this.paramClick(this.tcItem);
      } else if (item == '重启'){
        this.restartClick(this.tcItem);
      } else if (item == '暂停'){
        this.pauseClick(this.tcItem);
      } else if (item == '终止'){
        this.stopClick(this.tcItem);
      } else if (item == '详情'){
        this.detailClick(this.tcItem);
      }
    },

    //弹窗
    tcClick(){  
      this.isTc = false;
    },


    //子币对消息点击
    msgClick(executeId) {
      navigator.open(T("策略消息"), 'strategy/StrategyNotice', { stId: executeId });
    },

    //子币对参数点击
    paramClick(item) {
      var states = item.states;
      if (states == "STARTING" || states == "STOPING" ) {
        modal.toast('请勿频繁操作');
        return;
      }

      var param = {'executeId':item.executeId, 
                  'states':item.states,

                  'configMap':item.config};
      navigator.open('', 'run/RunParamz',param);
    },

    //子币对暂停点击
    pauseClick(item) {
      var states = item.states;
      if (states == "STARTING" || states == "STOPING" ) {
        modal.toast('请勿频繁操作');
        return;
      }
      
      amStrategy2.httpStip(item.executeId, false, ()=>{
        broadcast.send(broadcast.EXECUTE_UPDATE);
      });
    },

    //子币对重启点击
    restartClick(item) {
      var states = item.states;
      if (states == "STARTING" || states == "STOPING" ) {
        modal.toast('请勿频繁操作');
        return;
      }

     
      var api =  this.detailMap.states == 'SUSPEND' && this.pair.api;
      amStrategy2.showServers(true, api, (server)=>{
 
        var param = {'executeId':item.executeId};
        if (server) {
          param['serverCode'] = server.serverCode;
        }
        amStrategy2.restart(param, ()=>{
            modal.toast(T('重启成功'));
            broadcast.send(broadcast.EXECUTE_UPDATE);
        });
      });
    },

    //子币对终止点击
    stopClick(item) {
      var states = item.states;
      if (states == "STARTING" || states == "STOPING" ) {
        modal.toast('请勿频繁操作');
        return;
      }
      

      var config = item.config;
      var param = {'cancelOrder':config.cancelOrder,
                  'isConvert':config.isConvert};
      navigator.openDialog('run/RunStop', param);

      broadcast.subscribeOnce('RunStop', (map)=>{
        
        var pair = this.configMap.tradePairs[0];
        var apiId = pair.apiId;
        var param = {'executeId':item.executeId, 
                    'apiId':apiId, 
                    'cancelOrder':map.cancelOrder, 
                    'isConvert':map.isConvert,
                    'isMany':true};
        amStrategy2.httpEnd(param,()=>{
          broadcast.send(broadcast.EXECUTE_UPDATE);
        });
      });
    },

    //子币对详情点击
    detailClick(item) {
      var param = { executeId: item.executeId };
      navigator.open("", 'run/RunInfosz', param);
    },

    //菜单点击
    menuClick(item) {
      this.hideClick();

      if (item == "消息") {
        navigator.open(T("策略消息"), 'strategy/StrategyNotice', { stId: this.executeId });
        return;
      }
      
      if (item == "历史记录") {
        var param = {'executeId':this.executeId, 'investCoin':this.pair.investCoin};
        navigator.open("", 'strategy/StrategyChildRecord', param);
        return;
      }

      var states = this.detailMap.states;
      if (states == "STARTING" || states == "STOPING" ) {
        modal.toast('请勿频繁操作');
        return;
      }
      
      if (item == '暂停') {

        amStrategy2.httpStip(this.executeId, true, ()=>{
          modal.toast(T('暂停成功'));
          broadcast.send(broadcast.EXECUTE_UPDATE);
        });
        return;
      }

      if (item == '终止') {

        var param = {'cancelOrder':this.configMap.cancelOrder,
                    'isConvert':this.configMap.isConvert};
        navigator.openDialog('run/RunStop', param);

        broadcast.subscribeOnce('RunStop', (map)=>{
          
          var pair = this.configMap.tradePairs[0];
          var apiId = pair.apiId;
          var param = {'executeId':this.executeId, 
                      'apiId':apiId, 
                      'cancelOrder':map.cancelOrder, 
                      'isConvert':map.isConvert,
                      'isMany':true};
          amStrategy2.httpEnd(param,()=>{
            navigator.back();
            broadcast.send(broadcast.EXECUTE_UPDATE);
          });
        });
        return;
      }

      if (item == "加仓") {
        
        var sonExexuteIds = [];
        for (let index = 0; index < this.holdList.length; index++) {
          var hold = this.holdList[index];
          sonExexuteIds.push(hold.executeId);
        }

        var limitMap = this.detailMap.isFollow ? this.detailMap.followInvestLimit : this.followMap;

        var pair = this.configMap.tradePairs[0];
        var apiId = pair.apiId;
        var apiName = pair.apiName;
        amStrategy2.checkApi(apiId, apiName, (api)=>{
          var param = {'api':api,
                      'executeId':this.executeId, 
                      'states':this.detailMap.states,
                      'configMap':this.configMap,
                      'limitMap':limitMap,
                      'sonExexuteIds':sonExexuteIds};
          navigator.open('', 'run/RunAddInvestMany',param);
        });
        return;
      }
      
      if (item == "参数") {

        var param = {'executeId':this.executeId, 
            'strategyName':this.detailMap.followName ? this.detailMap.followName : this.detailMap.strategyName,
            'states':this.detailMap.states,
            'holdList':this.holdList,
            
            'configMap':this.configMap,
            'followMap':this.followMap,
            'isOpenFollow':this.detailMap.isOpenFollow,
            'followMimic':this.followMimic};
        navigator.open('', 'run/RunParams',param);
        return;
      }
      
      if (item == '重启') {
          
        amStrategy2.showServers(true, this.pair.api, (server)=>{
          var sonExexuteIds = [];
          for (let index = 0; index < this.holdList.length; index++) {
            var hold = this.holdList[index];
            sonExexuteIds.push(hold.executeId);
          }
          var param = {'executeId':this.executeId,
                      'sonExexuteIds':sonExexuteIds};
          if (server) {
            param['serverCode'] = server.serverCode;
          }
          amStrategy2.restarts(param, ()=>{
            modal.toast(T('重启成功'));
            broadcast.send(broadcast.EXECUTE_UPDATE);
          });
        });
        return;
      }
      

      if (item == "增加币对") {
        
        var pair = this.configMap.tradePairs[0];
        if (pair.apiId == '' && !this.manyMimic){
          modal.alert('模拟账户不支持增加币对');
          return;
        }
        
        if (this.holdList.length >= 20) {
          modal.toast(T('最多支持20个交易对'));
          return;
        }

        modal.showLoad();
        var param = {exchangeId: pair.exchangeId,
                    counterCoinId: pair.counterCoinId,
                    baseCoinId: pair.baseCoinId};
        weexHttp.post("quoteV3/querySinglePair",param,true,(data) => {
            modal.hideLoad();
            if (data.status == 200) {
              var pairMap = data.data;
              pairMap['baseCoinUsdPrice'] =  math.chu(pairMap.usdPrice, pairMap.last, math.getNumber(pairMap.baseCoinDecimal));

              //最大币对数：总投入 / 1000(折合当前价格)
              var price = (this.pair.investCoin == pairMap.baseCoin) ? pairMap.baseCoinUsdPrice : pairMap.counterCoinUsdPrice;
              var num = math.chu('1000', price);
              var maxPairNumber = math.chu(this.pair.investCoinnNum, num, 0, 2);
              maxPairNumber = math.getNumber(maxPairNumber) > 20 ? 20 : maxPairNumber;

              if (this.holdList.length >= maxPairNumber) {
                modal.toast(T('按照您当前投入的资金数，最大可支持&{1}个币对交易').replace("&{1}", maxPairNumber));
                return;
              }

              amStrategy2.checkApi(pair.apiId, pair.apiName, (api)=>{

                var param = {
                  'executeId': this.executeId,
                  'holdList': this.holdList,
                  'pairMap':pairMap,
                  'api':api,
                  'maxPairNumber':maxPairNumber,
                };
                navigator.open("", 'run/RunAddPair', param);
              });
            } else {
              modal.toast(data.msg);
            }
          }
        );
        return;
      }
    },
  },

};
</script>

 
<style src="@/_css/style.css"></style>
<style scoped>
.tc {
  position:absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color:rgba(0,0,0,0.4);
}
.tc-content {
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding-bottom: 40px;
}


.scroller {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9;
}

.wrapper {
  width: 750px;
  padding: 44px;
}

.line {
  margin-top: 40px;
  width: 710px;
  height: 2px;
  margin-bottom: 40px;
}

.line2 {
  margin-top: 40px;
  width: 750px;
  height: 2px;
  margin-bottom: 20px;
}
.line3 {
  height: 1px;
}
.width6700 {
  width: 670px;
}

.floatText {
  line-height: 40px;
}

.text-right {
  text-align: right;
}
.text-center {
  text-align: center;
}

.text68 {
  height: 68px;
  line-height: 68px;
}

.all2 {
  flex: 2;
}

.all3 {
  flex: 3;
}

/*走势图*/
.line-chart {
  margin-top: 40px;
  flex: 1;
  height: 450px;
}
.line-chart-color{
  width: 20px;
  height: 12px;
  border-radius: 2px;
  
  margin-right: 20px;
}
.image{
  width: 56px;
  height: 56px;
  border-radius: 28px;
  margin-right: 40px;
}
/*********************************** 菜单*/
.menu{
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 9;
}

.meun-content {
  position: absolute;
  width: 204px;
  border-radius: 4px;
  
  padding-top: 20px;
  padding-bottom: 20px;

  top: 0;
  right: 0;
}

.meun-text {
  height: 80px;
  line-height: 80px;
  width: 204px;
  text-align: center;
}

/*********************************** 持仓*/
.cell {
  flex-direction: row;
  align-items: center;
  height: 96px;
}
.cell-exch-bg{
  flex-direction: row;
  justify-content: flex-end;
  width: 662px;
}
.cell-exch {
  flex-direction: row;
  align-items: center;

  border-radius: 4px;
  border-width: 2px;

  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 14px;
  padding-right: 14px;
  
  margin-top: 20px;

  margin-left: 40px;
}

.img-bg {
  width: 22px;
  height: 14px;
}
.msg{
  width: 24px;
  height: 24px;
  margin-left: 10px;
}


/*********************************** 公共的*/
.height20 {
  height: 20px;
}

.height40 {
  height: 40px;
}
</style>
